package test.study.kits.excel.demo.demo2;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class TeamInfoListener extends AnalysisEventListener<TeamInfoData> {

    private static final int BATCH_COUNT = 100;

    @Getter
    private List<TeamInfoData> dataLt = new ArrayList<>();

    public void invoke(TeamInfoData data, AnalysisContext context) {
        //log.info(">>>>>> {}", data);
        dataLt.add(data);
//        if (dataLt.size() >= BATCH_COUNT) {
//            log.info("save size: {}", dataLt.size());
//            //存储完成清理 list
//            dataLt.clear();
//        }
    }

    public void doAfterAllAnalysed(AnalysisContext context) {
        log.info("save size: {}", dataLt.size());
        //这里也要保存数据，确保最后遗留的数据也存储到数据库
        log.info("所有数据解析完成！");
    }
}
